<?php
/**
 * Created by JetBrains PhpStorm.
 * User: fenglangyj
 * Date: 13-5-29
 * Time: 下午7:03
 * To change this template use File | Settings | File Templates.
 */
class Sdf_gii_model extends  SDF_Model{
    public $_field_comment = array();
    public $_field_data = array();

    public function __construct(){
        $this->load->database();
        parent::__construct();
    }
    /**
     * 获取字段详细信息
     * @return array|mixed
     */
    public function _field_data(){
        if(!empty($this->_field_data)){
            return $this->_field_data;
        }
        $this->_field_comment();
        $list = $this->db->field_data($this->_table);
        foreach($list as $vo){
            $this->_field_data[] = array(
                'name'=>$vo->name,
                'type'=>$vo->type,
                'default'=>$vo->default,
                'max_length'=>$vo->max_length,
                'primary_key'=>$vo->primary_key,
                'comment'=> $this->_field_comment[$vo->name],
            );
        }
        return $this->_field_data;
    }

    /**
     * 获取表字段的注释列表
     * @return array
     */
    public function _field_comment(){
        if(!empty($this->_field_comment)){
            return $this->_field_comment;
        }
        $list = $this->db->query("select column_name, column_comment from information_schema.columns where table_name = '".$this->db->dbprefix.$this->_table."'")->result_array();
        foreach($list as $vo){
            $this->_field_comment[$vo['column_name']] = $vo['column_comment'];
        }
        return $this->_field_comment;
    }
}
